package se.webbzon.oschi01.utilities;

public class FileUtils {
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the filename of the given path. **/
	public static String getFilename(String path) {
		String separator = System.getProperty("file.separator");
	    int lastSeparatorIndex = path.lastIndexOf(separator);
	    if (lastSeparatorIndex == -1)
	        return path;
	    else
	        return path.substring(lastSeparatorIndex + 1);
	}
	
	/** Removes the extension of a file with the given filename. **/
	public static String removeExtension(String filename) {
	    int extensionIndex = filename.lastIndexOf(".");
	    if (extensionIndex == -1)
	        return filename;
	    else
	    	return filename.substring(0, extensionIndex);
	}
	
	/** Returns the extension of a file with the given filename. **/
	public static String getExtension(String filename) {
		int extensionIndex = filename.lastIndexOf(".");
	    if (extensionIndex == -1)
	        return "";
	    else
	    	return filename.substring(extensionIndex + 1);
	}

}
